package com.micro.train.repository;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.micro.train.entity.SeatInventory;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.time.LocalDate;
import java.util.List;

/**
 * 座位库存状态Repository
 */
@Mapper
public interface SeatInventoryRepository extends BaseMapper<SeatInventory> {

    /**
     * 根据座位ID和基准日期查询库存状态
     */
    SeatInventory selectBySeatIdAndBaseDate(@Param("seatId") Long seatId, @Param("baseDate") LocalDate baseDate);

    /**
     * 根据列车ID和基准日期查询所有库存状态
     */
    List<SeatInventory> selectByTrainIdAndBaseDate(@Param("trainId") Long trainId, @Param("baseDate") LocalDate baseDate);

    /**
     * 根据列车ID查询最新的库存状态
     */
    List<SeatInventory> selectLatestByTrainId(@Param("trainId") Long trainId);

    /**
     * 检查指定座位和基准日期是否存在库存记录
     */
    Boolean existsBySeatIdAndBaseDate(@Param("seatId") Long seatId, @Param("baseDate") LocalDate baseDate);

    /**
     * 删除过期的库存记录（基准日期早于指定日期）
     */
    int deleteExpiredInventory(@Param("expireDate") LocalDate expireDate);

    /**
     * 批量插入库存记录
     */
    int batchInsert(@Param("inventories") List<SeatInventory> inventories);

    /**
     * 根据列车ID和座位类型查询库存状态
     */
    List<SeatInventory> selectByTrainIdAndSeatType(@Param("trainId") Long trainId, @Param("seatType") Integer seatType, @Param("baseDate") LocalDate baseDate);
}
